<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html>
<jsp:include page="../common/import.jsp" flush="true"></jsp:include>
<body>

<jsp:include page="../common/header.jsp" flush="true"></jsp:include>
<div class="main p20">
	<div class="container clear">
        <ul class="left-nav fl pt20 w200">
            <li><a href="${base}/agent/user/personalCenter.xhtml"><span class="iconfont">&#xf014b;</span>个人信息</a></li>
            <li><a class="ahover" href="${base}/agent/user/pwPage.xhtml"><span class="iconfont">&#xf014d;</span>修改密码</a></li>
        </ul>
        
        <div class="main-right fr">
        	<div class="b m20 b-radius">
            	<div class="clear bgf5 bb">
                	<h2 class="fl h30 lg30 p5 pl10">修改密码</h2>
                    <a href="javascript:" class="fr h20 p5 m5 w50 bg1eb9ef cfff b-radius tc" onclick="back()">返回</a>
                </div>
                
                <div class="p30 mt20">
                    <div class="clear mt20">
                    	<span class="fl w250 tr fb h20 lg20 p5">旧密码：</span>
                        <input id="oldPassword" class="fl w400 h20 p5 b-radius" type="password">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w250 tr fb h20 lg20 p5">新密码：</span>
                        <input id="newPassword" class="fl w400 h20 p5 b-radius" type="password">
                    </div>
                    
                    <div class="clear mt20">
                    	<span class="fl w250 tr fb h20 lg20 p5">确认密码：</span>
                        <input id="againPassword" class="fl w400 h20 p5 b-radius" type="password">
                    </div>

                    <div class="tc p50">
                        <button id="submit" class="w100 bgac1 cfff h20 p10 ml30 b-radius" onclick="changePassword()">提交</button>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
</div>

<!--保存失败弹框-->
<div class="none" id="erro">
	<div class="fixed-bg"></div>
    <div class="pop-up-box">
    	<div class="clear"><button class="iconfont fr p10 c666 btn-close">&#xf00b3;</button></div>
    	<p class="f20 lg20 tc mt50"><span class="iconfont icon-false">&#xf0155;</span><a id="erroInfo">保存不成功！</a></p>
    </div>
</div>
<div class="none" id="erro1">
	<div class="fixed-bg"></div>
    <div class="pop-up-box">
    	<div class="clear"><button class="iconfont fr p10 c666 btn-close">&#xf00b3;</button></div>
    	<p class="f20 lg20 tc mt50"><span class="iconfont icon-false">&#xf0155;</span>保存不成功！</p>
    </div>
</div>

<div class="none" id="erro2">
	<div class="fixed-bg"></div>
    <div class="pop-up-box">
    	<div class="clear"><button class="iconfont fr p10 c666 btn-close">&#xf00b3;</button></div>
    	<p class="f20 lg20 tc mt50"><span class="iconfont icon-false">&#xf0155;</span>原密码错误！</p>
    </div>
</div>

<div class="none" id="erro3">
	<div class="fixed-bg"></div>
    <div class="pop-up-box">
    	<div class="clear"><button class="iconfont fr p10 c666 btn-close">&#xf00b3;</button></div>
    	<p class="f20 lg20 tc mt50"><span class="iconfont icon-false">&#xf0155;</span>两次输入密码不一致！</p>
    </div>
</div>
<!--保存失败弹框end-->
<input id="userId" value="${user.id}" hidden="true">
<jsp:include page="../common/footer.jsp" flush="true"></jsp:include>

<script type="text/javascript">
function changePassword(){
	var userId = document.getElementById("userId").value;
	var oldPassword = document.getElementById("oldPassword").value;
	var newPassword = document.getElementById("newPassword").value;
	var againPassword = document.getElementById("againPassword").value;
	if (oldPassword==null||oldPassword=='') {
		$("#erroInfo").text("原密码不能为空");
    	$("#erro").slideToggle();
    	alert("原密码不能为空!");
		return ;
	}
	if (newPassword==null||newPassword=='') {
		$("#erroInfo").text("新密码不能为空");
    	$("#erro").slideToggle();
    	alert("新密码不能为空!");
		return ;
	}
	if (againPassword==null||againPassword=='') {
		$("#erroInfo").text("确认密码不能为空");
    	$("#erro").slideToggle();
    	alert("确认密码不能为空!");
		return ;
	}
	var data = {"userId":userId,"oldPassword":oldPassword,"newPassword":newPassword,"againPassword":againPassword};
	var url = "${base}/agent/user/changePassword.xhtml";
	$.ajax({
        url: url,
        type: "POST",
        data: data,
        dataType: "json",
        success: function (data) {
        	
        	$("#erroInfo").text(data.info);
        	$("#erro").slideToggle();
        	if (data.status==1) {
        		alert(data.info);
				window.location.href="${base}/agent/user/changePwSuccess.xhtml";
			}
        	//alert(data.info);
        	if (data.status==0) {
        		alert(data.info);
	        	location.reload(true);
			}
        },
        error: function (data) {
        	$("#erro1").slideToggle();
            alert('服务端报错，' + data.status);
        }
    });
}
function back(){
	
	window.location.href="${base}/agent/user/personalCenter.xhtml";
}
</script>
</body>
</html>